﻿using System;
using System.Web;
using System.Xml.Linq;
using System.Web.UI.HtmlControls;

namespace RN.ERP.Web.Download
{
    public partial class FileDownload : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            BindFileList();
        }

        private void BindFileList()
        {
            string url = HttpContext.Current.Request.MapPath("~/Download/FileData.xml");
            XDocument doc = XDocument.Load(url);

            foreach (var file in doc.Root.Elements("file"))
	        {
                HtmlGenericControl tr = new HtmlGenericControl();
                tr.TagName = "tr";
                string note = file.Attribute("note").Value;
                if (string.IsNullOrEmpty(note))
                {
                    note = "";
                }
                else
                {
                    note = string.Format("<h2 class='gray note'>{0}</h2>", note);
                }

                tr.InnerHtml = string.Format(@"
                    <td width=80%>{0}{3}</td>
                    <td width=10%>{1}</td>
                    <td width=10%><a href='{2}'><img src='../Styles/skins/ytblue/images/xz_icon.png' width='78' height='22'></a></td>
                ", file.Attribute("name").Value, file.Attribute("updateDate").Value
                 , file.Attribute("url").Value, note);
                FileList.Controls.Add(tr);
	        }            
        }
    }
}